package com.theo.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.theo.entity.CommentInfo;
import com.theo.entity.TopicInfo;
import com.theo.entity.TypeInfo;
import com.theo.service.CommentInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 方涛
 * @since 2021-02-02
 */
@Controller
@RequestMapping("/comment-info")
public class CommentInfoController {

    @Autowired
    private CommentInfoService commentInfoService;
    @RequestMapping("/show.do")
    public String showCommentInfo(Model model, @RequestParam(value = "pn", defaultValue = "1") Integer pn) {
        PageHelper.startPage(pn, 8);
        List<CommentInfo> commentInfos = commentInfoService.queryAllCommentInfo();
        PageInfo pageInfo = new PageInfo(commentInfos, 2);
        model.addAttribute("pageInfo", pageInfo);
        return "admin/comment_list";
    }

    @RequestMapping("/delete.do")
    public String deleteCommentInfo(Integer id) {
        commentInfoService.deleteCommentInfo(id);
        return "redirect:/comment-info/show.do";
    }

    @RequestMapping("/deleteSelf.do")
    public String deleteCommentSelf(Integer id) {
        commentInfoService.deleteCommentInfo(id);
        return "redirect:/comment-info/show.do";
    }
}

